package com.lw.lwte.common.enums;


import com.lw.lwte.common.helper.StringHelper;

/**
 * @author liuwei
 * @date 2024/10/30
 * @description Http请求方法枚举
 */
public enum HttpMethod {
    GET(0, "GET"),

    POST(1, "POST"),

    HEAD(2, "HEAD"),

    PUT(3, "PUT"),

    DELETE(4, "DELETE"),

    TRACE(5, "TRACE"),

    PATCH(6, "PATCH"),

    OPTION(7, "OPTION"),

    UPLOAD(8, "UPLOAD"),

    DOWNLOAD(9, "DOWNLOAD");

    private int code;
    private String name;

    HttpMethod(int code, String name) {
        this.code = code;
        this.name = name;
    }

    public int getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    @Override
    public String toString() {
        return name;
    }

    public static HttpMethod getMethod(String methodName) {
        if(StringHelper.isBlank(methodName)) {
            return null;
        }

        for(HttpMethod value : HttpMethod.values()) {
            if(StringHelper.equalsIgnoreCase(methodName, value.getName())) {
                return value;
            }
        }

        throw new IllegalArgumentException("Not existed name with: " + methodName + " http request.");
    }
}